package com.tanhua.server.controller;

import com.tanhua.server.service.SoulService;
import com.tanhua.server.pojo.Answers;
import com.tanhua.server.vo.QuestionnaireVo;
import com.tanhua.server.vo.TestResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
@Slf4j
public class SoulController {

    @Autowired
    private SoulService soulService;

    /*
     * 问卷列表
     * */
    @GetMapping
    public List<QuestionnaireVo> SoulQuestionnaire() {

        List<QuestionnaireVo> questionnaireVoList = soulService.SQuestionnaireLike();
        return questionnaireVoList;
    }

    /*
     * 提交问卷
     * */
    @PostMapping
    public String TestSoul(@RequestBody Map<String, List<Answers>> param) {
        /*List<Answers> answersList = param.get("answers");*/

        String reportId = this.soulService.testSoul(param);
        return reportId;
    }

    /*
     * 测试结果
     * */
    @GetMapping("/report/{id}")
    public ResponseEntity<TestResultVo> TestReport(@PathVariable("id") Long id) {
        try {
            TestResultVo testResultVo = this.soulService.testReport(id);
            return ResponseEntity.ok(testResultVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
